﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BTGISWASECO.DataLayer;
using BTGISWASECO.BusinessEntities;
using BTGISWASECO.BusinessLayer;

public partial class PresentationLayer_DefaultTab : System.Web.UI.Page
{
    DiemDauNoiBLL bll = new DiemDauNoiBLL();
    DMHuongDongChayDAL DMHuongDongChayDal = new DMHuongDongChayDAL();
    DiemDauNoiEntities DiemDauNoiEntities = new DiemDauNoiEntities();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["DataTable"] == "")
                Response.Redirect("../default.aspx");
            DiemDauNoiEntities = bll.GetDiemDauNoiEntitiesByID();
            txtObjectID.Value = DiemDauNoiEntities.OBJECTID.ToString();
            txtIDOngNoi.Text = DiemDauNoiEntities.IDDiemDauNoi;
            this.txtDMA.Text = DiemDauNoiEntities.IDDMA;
            this.txtDMZ.Text = DiemDauNoiEntities.IDDMZ;
            this.txtTen.Text = DiemDauNoiEntities.Ten;
            this.txtNgayCNC.Text = DiemDauNoiEntities.NgayCNCuoi.ToString("dd/MM/yyyy");
            this.txtNguoiCNC.Text = DiemDauNoiEntities.NguoiCNCuoi.ToString();
            this.txtMaHinhAnh.Text = DiemDauNoiEntities.IDHinhAnh;
            this.txtGhiChu.Text = DiemDauNoiEntities.GhiChu;

            foreach (var itemtc in DMTieuChuanOngNoiDAL.GetList())
            {
                if (DiemDauNoiEntities.TieuChuanText.ToString().Trim() == itemtc.MoTa.ToString().Trim())
                    DiemDauNoiEntities.TieuChuan = itemtc.Ma;
                ListItem iteml = new ListItem(itemtc.MoTa.ToString(), itemtc.Ma.ToString());
                DListTieuChuan.Items.Add(iteml);
            }
            DListTieuChuan.SelectedValue = DiemDauNoiEntities.TieuChuan.ToString();

            foreach (var itemkcv in DMKichCoOngDAL.GetList())
            {
                if (DiemDauNoiEntities.KichCoText.ToString().Trim() == itemkcv.MoTa.ToString().Trim())
                    DiemDauNoiEntities.KichCo = itemkcv.Ma;
                ListItem iteml = new ListItem(itemkcv.MoTa.ToString(), itemkcv.Ma.ToString());
                DListKichCoOng.Items.Add(iteml);
            }
            if (DiemDauNoiEntities.KichCo != null)
            DListKichCoOng.SelectedValue = DiemDauNoiEntities.KichCo.ToString();

            foreach (var itemlv in DMLoaiOngNoiDAL.GetList())
            {
                if (DiemDauNoiEntities.LoaiOngNoiText.ToString().Trim() == itemlv.MoTa.ToString().Trim())
                    DiemDauNoiEntities.LoaiOngNoi = itemlv.Ma;
                ListItem iteml = new ListItem(itemlv.MoTa.ToString(), itemlv.Ma.ToString());
                DListLoaiOngNoi.Items.Add(iteml);
            }
            if (DiemDauNoiEntities.LoaiOngNoi != null)
                DListLoaiOngNoi.SelectedValue = DiemDauNoiEntities.LoaiOngNoi.ToString();


           foreach (var itemnttsd in DMTinhTrangSDDAL.GetList())
            {
                if (DiemDauNoiEntities.TinhTrangText.ToString().Trim() == itemnttsd.MoTa.ToString().Trim())
                    DiemDauNoiEntities.TinhTrang = itemnttsd.Ma;
                ListItem iteml = new ListItem(itemnttsd.MoTa.ToString(), itemnttsd.Ma.ToString());
                DListTTSD.Items.Add(iteml);
            }
            DListTTSD.SelectedValue = DiemDauNoiEntities.TinhTrang.ToString();

            foreach (var itemntldv in DMLoaiDonViDAL.GetList())
            {
                if (DiemDauNoiEntities.DonViQLText.ToString().Trim() == itemntldv.MoTa.ToString().Trim())
                    DiemDauNoiEntities.DonViQL = itemntldv.Ma;
                ListItem iteml = new ListItem(itemntldv.MoTa.ToString(), itemntldv.Ma.ToString());
                DListDonViQL.Items.Add(iteml);
            }
            DListDonViQL.SelectedValue = DiemDauNoiEntities.DonViQL.ToString();

            foreach (var itemtsh in DMThuocSoHuuDAL.GetList())
            {
                if (DiemDauNoiEntities.ThuocSoHuuText.ToString().Trim() == itemtsh.MoTa.ToString().Trim())
                    DiemDauNoiEntities.ThuocSoHuu = itemtsh.Ma;
                ListItem iteml = new ListItem(itemtsh.MoTa.ToString(), itemtsh.Ma.ToString());
                DListThuocSoHuu.Items.Add(iteml);
            }
            DListThuocSoHuu.SelectedValue = DiemDauNoiEntities.ThuocSoHuu.ToString();

        }//ThuocSoHuu
    }
    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        DiemDauNoiEntities bk = new DiemDauNoiEntities();
        DiemDauNoiDAL DiemDauNoiDAL = new DiemDauNoiDAL();
        //DiemDauNoiEntities DiemDauNoiEntities = new DiemDauNoiEntities(Convert.ToInt32(DListDonViTC.SelectedValue = DListDonViTC.SelectedValue!=""?DListDonViTC.SelectedValue:"0"),
        //    Convert.ToInt32(DListDonViGS.SelectedValue = DListDonViGS.SelectedValue!=""?DListDonViGS.SelectedValue:"0"), this.txtNguoiCNC.Text, DateTime.Parse(this.txtNgayCNC.Text.ToString()), this.txtGhiChu.Text, this.txtMaHinhAnh.Text);
        DiemDauNoiEntities DiemDauNoiEntities = new DiemDauNoiEntities(Convert.ToInt32(txtObjectID.Value), this.txtIDOngNoi.Text,this.txtDMZ.Text, this.txtDMA.Text,
           Convert.ToInt32(DListTieuChuan.SelectedValue = DListTieuChuan.SelectedValue != "" ? DListTieuChuan.SelectedValue : "0"), 
           Convert.ToInt32(DListTTSD.SelectedValue = DListTTSD.SelectedValue != "" ? DListTTSD.SelectedValue : "0"),
           Convert.ToInt32(DListDonViQL.SelectedValue = DListDonViQL.SelectedValue != "" ? DListDonViQL.SelectedValue : "0"),
           DListKichCoOng.SelectedValue = DListKichCoOng.SelectedValue != "" ? DListKichCoOng.SelectedValue : "",
           DListLoaiOngNoi.SelectedValue = DListLoaiOngNoi.SelectedValue != "" ? DListLoaiOngNoi.SelectedValue : "", 
           Convert.ToInt32(DListThuocSoHuu.SelectedValue = DListThuocSoHuu.SelectedValue != "" ? DListThuocSoHuu.SelectedValue : "0"),
           Convert.ToInt32(this.nSLKPSuCo.Text), DateTime.Parse(Request.Form.Get("txtNgayCNC")), this.txtNguoiCNC.Text, this.txtMaHinhAnh.Text, this.txtGhiChu.Text, this.txtTen.Text);
        DiemDauNoiDAL.Update1(DiemDauNoiEntities);
        //DiemDauNoiDAL.Update(Convert.ToInt32(txtObjectID.Value), txtMaDoanOng.Text, txtDMA.Text, Convert.ToInt32(DListHDChay.SelectedValue), Convert.ToDouble(this.nChieuDai.Text));
        ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script language='JavaScript'>alert('Cập nhật thành công'); window.location.href ='../Default.aspx';</script>");

    }
    protected void btnHuyBo_Click(object sender, EventArgs e)
    {
        Response.Redirect("../default.aspx");
    }
}